<template>
  <div class="login-wrap">
    <div class="login-box">
      <div class="block">
        <el-avatar :size="50" ></el-avatar>
      </div>
      <el-form ref="form" :model="form" label-width="80px" class="login-form">
        <el-form-item label="用户名">
          <el-input v-model="form.username"></el-input> </el-form-item
        ><el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="login-btn" @click="onSubmit">登录</el-button>
          <!-- <el-button>取消</el-button> -->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import request from "../../utils/request";
import "../../utils/api"

export default {
  data() {
    return {
      form: {
        username: "",
        password:"",
      },
    };
  },
  methods: {
    onSubmit() {
      // console.log("登录");
      request.get("/api/login").then(res=>{
        // console.log(res.data);
        this.$message({
          message: res.data.message,
          type: 'success'
        });
        window.localStorage.setItem("token",res.data.token);
        this.$router.push('/')
        // window.location.reload()
      })
    },
  },
};
</script>

<style scoped lang='scss'>
.login-wrap {
  width: 100%;
  height: 100%;
  background-color: rgb(25, 22, 62);
  .login-box {
    width: 500px;
    height: 300px;
    // background-color: #fff;
    color: #ccc;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 5%;
    // display: flex;
    // flex-direction: column;
    // justify-content: center;
    // align-items: center;
    text-align: center;
    .block {
      margin: 20px 0;
    }
    .login-btn{
      margin-left: -70px;
      width: 60%;
      text-align: center;
    }
  }
}
</style>